<template>
  <app-layout viewName="crm_leadchartview9" viewTitle="线索/商机图表视图" :isShowToolbar="false" :className="{ 'view-container': true, 'default-mode-view': true, 'dechartview9': true, 'crm-lead-chart-view9': true }" layoutMode="VIEW" :isShowUserInfo="isDefaultView()" :openMode="openMode" @close-view="closeView($event)">
    <template slot="headerLeft">
      <div class="view-header-left">

        <div class="view-caption" v-if="isDefaultView()">{{$t(model.srfCaption)}}</div>
        <modal-breadcrumb v-if="isModalView()"/>
      </div>
    </template>
    <template slot="content">
      <div class="view-content-wrapper">
        
<view_searchform 
    :viewState="viewState"  
    :viewparams="viewparams" 
    :context="context" 
    :showBusyIndicator="true"
    v-show="isExpandSearchForm"
    loaddraftAction="FilterGetDraft"
    loadAction="FilterGet"

    name="searchform"  
    ref='searchform' 
    @save="searchform_save($event)"  
    @search="searchform_search($event)"  
    @load="searchform_load($event)"  
    @closeview="closeView($event)">
</view_searchform>
<view_chart 
    :viewState="viewState"  
    :viewparams="viewparams" 
    :context="context" 
    fetchAction="FetchDefault"
    :showBusyIndicator="true" 
    name="chart"  
    ref='chart' 
    @beforeload="chart_beforeload($event)"  
    @load="chart_load($event)"  
    @closeview="closeView($event)">
</view_chart>


      </div>
    </template>
  </app-layout>
</template>

<script lang='tsx'>
import { Vue, Component, Prop, Provide, Emit, Watch } from 'vue-property-decorator';
import { Subject } from 'rxjs';
import { UIActionTool, Util } from '@/utils';
import { VueLifeCycleProcessing, ChartView9Base } from '@/crm-core';
import Crm_leadService from '@/service/crm-lead/crm-lead-service';

import ChartView9Engine from '@engine/view/chart-view9-engine';


/**
 * 线索/商机图表视图基类
 *
 * @export
 * @class Crm_leadChartView9Base
 * @extends {ChartView9Base}
 */
@Component({})
@VueLifeCycleProcessing
export default class Crm_leadChartView9Base extends ChartView9Base {

    /**
     * 实体服务对象
     *
     * @type {Crm_leadService}
     * @memberof Crm_leadChartView9Base
     */
    public appEntityService: Crm_leadService = new Crm_leadService;

    /**
     * 数据变化
     *
     * @param {*} val
     * @returns {*}
     * @memberof Crm_leadChartView9Base
     */
    @Emit() 
    public viewDatasChange(val: any):any {
        return val;
    }

	/**
	 * 视图标识
	 *
	 * @type {string}
	 * @memberof Crm_leadChartView9Base
	 */
	public viewtag: string = '94097c70afa7044f81beeb30e03f013d';

    /**
     * 父数据对象
     *
     * @protected
     * @type {*}
     * @memberof Crm_leadChartView9Base
     */
    protected srfparentdata: any = {};

	/**
	 * 自定义视图导航上下文集合
	 *
	 * @type {*}
	 * @memberof Crm_leadChartView9Base
	 */
    protected customViewNavContexts:any ={
    };

	/**
	 * 自定义视图导航参数集合
	 *
	 * @type {*}
	 * @memberof Crm_leadChartView9Base
	 */
    protected customViewParams:any ={
    };

    /**
     * 视图模型数据
     *
     * @type {*}
     * @memberof Crm_leadChartView9Base
     */
    public model: any = {
        srfCaption: 'entities.crm_lead.views.chartview9.caption',
        srfTitle: 'entities.crm_lead.views.chartview9.title',
        srfSubTitle: 'entities.crm_lead.views.chartview9.subtitle',
        dataInfo: ''
    }

    /**
     * 容器模型
     *
     * @type {*}
     * @memberof Crm_leadChartView9Base
     */
    public containerModel: any = {
        view_chart: { name: 'chart', type: 'CHART' },
        view_searchform: { name: 'searchform', type: 'SEARCHFORM' },
    };

    /**
     * 视图状态订阅对象
     *
     * @private
     * @type {Subject<{action: string, data: any}>}
     * @memberof Crm_leadChartView9Base
     */
    public viewState: Subject<ViewState> = new Subject();


    /**
     * 视图引擎
     *
     * @public
     * @type {Engine}
     * @memberof Crm_leadChartView9Base
     */
    public engine: ChartView9Engine = new ChartView9Engine();
	

    /**
     * 引擎初始化
     *
     * @public
     * @memberof Crm_leadChartView9Base
     */
    public engineInit(): void {
        this.engine.init({
            view: this,
            chart: this.$refs.chart,
            searchform: this.$refs.searchform,
            keyPSDEField: 'crm_lead',
            majorPSDEField: 'name',
            isLoadDefault: true,
        });
    }


    /**
     * chart 部件 beforeload 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Crm_leadChartView9Base
     */
    public chart_beforeload($event: any, $event2?: any) {
        this.engine.onCtrlEvent('chart', 'beforeload', $event);
    }


    /**
     * chart 部件 load 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Crm_leadChartView9Base
     */
    public chart_load($event: any, $event2?: any) {
        this.engine.onCtrlEvent('chart', 'load', $event);
    }


    /**
     * searchform 部件 save 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Crm_leadChartView9Base
     */
    public searchform_save($event: any, $event2?: any) {
        this.engine.onCtrlEvent('searchform', 'save', $event);
    }


    /**
     * searchform 部件 search 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Crm_leadChartView9Base
     */
    public searchform_search($event: any, $event2?: any) {
        this.engine.onCtrlEvent('searchform', 'search', $event);
    }


    /**
     * searchform 部件 load 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Crm_leadChartView9Base
     */
    public searchform_load($event: any, $event2?: any) {
        this.engine.onCtrlEvent('searchform', 'load', $event);
    }





    /**
     * 销毁视图回调
     *
     * @memberof Crm_leadChartView9Base
     */
    public destroyed(){
        if(this.viewDefaultUsage){
            let localStoreLength = Object.keys(localStorage);
            if(localStoreLength.length > 0){
                localStoreLength.forEach((item:string) =>{
                if(item.startsWith(this.context.srfsessionid)){
                    localStorage.removeItem(item);
                }
                })
            }
        }
    }

    /**
     * 搜索值
     *
     * @type {string}
     * @memberof Crm_leadChartView9
     */
    public query: string = '';

    /**
     * 是否展开搜索表单
     *
     * @type {boolean}
     * @memberof Crm_leadChartView9
     */
    public isExpandSearchForm: boolean = false;

    /**
     * 快速搜索
     *
     * @param {*} $event
     * @memberof Crm_leadChartView9
     */
    public onSearch($event: any): void {
        const refs: any = this.$refs;
        if (refs.chart) {
            refs.chart.refresh({});
        }
    }

}
</script>

<style lang='less'>
@import './crm-lead-chart-view9.less';
</style>